#include "StdAfx.h"
#include "ConstraintParam.h"

CConstraintParam::CConstraintParam(void)
	: m_pGradeConstraintParam(NULL)
	, m_iGradeConstraintNum(0)
	, m_pAbilityConstraintParam(NULL)
	, m_iAbilityConstraintNum(0)
	, m_pQuantityConstraintParam(NULL)
	, m_iTotalPeriod(1)
	, m_dShovelRadius(0)
{
}

CConstraintParam::~CConstraintParam(void)
{
	if (m_pGradeConstraintParam != NULL)
	{
		delete [] m_pGradeConstraintParam;
		m_pGradeConstraintParam = NULL;
	}

	if (m_pAbilityConstraintParam != NULL)
	{
		delete [] m_pAbilityConstraintParam;
		m_pAbilityConstraintParam = NULL;
	}

	if (m_pQuantityConstraintParam != NULL)
	{
		delete m_pQuantityConstraintParam;
		m_pQuantityConstraintParam = NULL;
	}
}

void CConstraintParam::SetGradeConstraintParam(const GRADE_CONSTRAINT_PARAM* pConstraintParam, int iConstraintNum)
{
	m_iGradeConstraintNum = iConstraintNum;
	if (m_pGradeConstraintParam != NULL)
	{
		delete [] m_pGradeConstraintParam;
		m_pGradeConstraintParam = NULL;
	}
	m_pGradeConstraintParam = new GRADE_CONSTRAINT_PARAM[m_iGradeConstraintNum];
	for (int i=0; i<m_iGradeConstraintNum; ++i)
	{
		m_pGradeConstraintParam[i].index = pConstraintParam[i].index;
		strcpy_s(m_pGradeConstraintParam[i].grade_name, pConstraintParam[i].grade_name);
		m_pGradeConstraintParam[i].compare_sign = pConstraintParam[i].compare_sign;
		m_pGradeConstraintParam[i].compare_value = pConstraintParam[i].compare_value;
	}
}

void CConstraintParam::SetAbilityConstraintParam(const CAPACITY_CONSTRAINT_PARAM* pConstraintParam, int iConstraintNum)
{
	m_iAbilityConstraintNum = iConstraintNum;
	if (m_pAbilityConstraintParam != NULL)
	{
		delete [] m_pAbilityConstraintParam;
		m_pAbilityConstraintParam = NULL;
	}
	m_pAbilityConstraintParam = new CAPACITY_CONSTRAINT_PARAM[m_iAbilityConstraintNum];
	for (int i=0; i<m_iAbilityConstraintNum; ++i)
	{
		m_pAbilityConstraintParam[i].m_iBlastPileID = pConstraintParam[i].m_iBlastPileID;
		m_pAbilityConstraintParam[i].m_dMaxAbility = pConstraintParam[i].m_dMaxAbility;
	}
}

void CConstraintParam::SetQuantityConstraintParam(bool bConstraint, int constr_type, double constr_value)
{
	if (m_pQuantityConstraintParam != NULL)
	{
		delete m_pQuantityConstraintParam;
		m_pQuantityConstraintParam = NULL;
	}

	m_pQuantityConstraintParam = new QUANTITY_CONSTRAINT_PARAM;
	m_pQuantityConstraintParam->bConstraint = bConstraint;
	m_pQuantityConstraintParam->compare_sign = constr_type;
	m_pQuantityConstraintParam->compare_value = constr_value;
}

bool CConstraintParam::GetGradeConstraintParam(GRADE_CONSTRAINT_PARAM*& pConstraintParam, int& iConstraintNum)
{
	if (NULL == m_pGradeConstraintParam || m_iGradeConstraintNum <= 0)
		return false;

	iConstraintNum = m_iGradeConstraintNum;
	pConstraintParam = m_pGradeConstraintParam;

	return true;
}

bool CConstraintParam::GetAbilityConstraintParam(CAPACITY_CONSTRAINT_PARAM*& pConstraintParam, int& iConstraintNum)
{
	if (NULL == m_pAbilityConstraintParam || m_iAbilityConstraintNum <= 0)
		return false;

	iConstraintNum = m_iAbilityConstraintNum;
	pConstraintParam = m_pAbilityConstraintParam;

	return true;	
}
